package 线程池的使用;

import org.apache.commons.lang3.StringUtils;
import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
import 线程池的使用.thread.ThreadPool;

import java.util.concurrent.*;

/**
 * @author yangjicong
 * @date 2022/1/19
 */
public class RunThread {
	/**
	 * BIZ层
	 */
	@Autowired(required = false)
	private static ActivityConfigBiz activityConfigBiz;

	public static int i = 0;
	public static void main(String[] args) {
		//Boolean aBoolean = testTme(100, 1500, 20L);

		//System.out.println("args = " + i);


		String ll = "1000.23";

		String[] split = ll.split("\\.");
		int length = split.length;
		System.out.println("ll = " + length);

		//异步处理
		// BatchActivityThreadHelper batchActivityThreadHelper = new BatchActivityThreadHelper(activityConfigBiz, infoBO, MDC.get(BestpayMarker.TRACE_LOG_ID));
		// ThreadPool.execute(batchActivityThreadHelper);
	}

	public static  void testThread() {
		// 示例
		long START = System.currentTimeMillis();
		ScheduledThreadPoolExecutor executor = new ScheduledThreadPoolExecutor(4);

		ScheduledFuture<?> scheduledFuture = executor.schedule(new Runnable() {
			@Override
			public void run() {
				System.out.println("延迟10秒执行");
				long END = System.currentTimeMillis();
				long start = END- START;

				System.out.println("END = " +start);
				return;
			}
		}, 10, TimeUnit.SECONDS);

		CompletableFuture<Boolean> future = CompletableFuture.supplyAsync(() -> Boolean.TRUE,
				ThreadPool.THREAD_POOL_EXECUTOR);

		try {
			Boolean aBoolean = future.get();
			System.out.println("aBoolean = " + aBoolean);
		} catch (InterruptedException e) {
			e.printStackTrace();
		} catch (ExecutionException e) {
			e.printStackTrace();
		}

	}
	public static  Boolean testTme(int initTime, int maxTime,long allTime) {
		if (allTime> maxTime){
			return Boolean.FALSE;
		}
		long startTime = System.currentTimeMillis();
		try {
			Thread.sleep(20);
		} catch (InterruptedException e) {
			e.printStackTrace();
		}
		long executeTime = System.currentTimeMillis() - startTime;
		System.out.println("executeTime = " + executeTime);

		long thisTime = allTime + executeTime;
		System.out.println("thisTime = " + thisTime);
		i++;
		return testTme(initTime, maxTime, thisTime);
	}

}
